<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.plugs.test &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="next" title="gozerlib.plugs.uniq" href="uniq.html" />
    <link rel="prev" title="gozerlib.plugs.tail" href="tail.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="uniq.html" title="gozerlib.plugs.uniq"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="tail.html" title="gozerlib.plugs.tail"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.plugs.test">
<h1>gozerlib.plugs.test<a class="headerlink" href="#module-gozerlib.plugs.test" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="gozerlib.plugs.test.dummy">
<tt class="descclassname">gozerlib.plugs.test.</tt><tt class="descname">dummy</tt><big>(</big><em>a</em>, <em>b=None</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.test.dummy" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.test.handle_forcedexception">
<tt class="descclassname">gozerlib.plugs.test.</tt><tt class="descname">handle_forcedexception</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.test.handle_forcedexception" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.test.handle_testhammer">
<tt class="descclassname">gozerlib.plugs.test.</tt><tt class="descname">handle_testhammer</tt><big>(</big><em>bot</em>, <em>msg</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.test.handle_testhammer" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.test.handle_testplugs">
<tt class="descclassname">gozerlib.plugs.test.</tt><tt class="descname">handle_testplugs</tt><big>(</big><em>bot</em>, <em>msg</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.test.handle_testplugs" title="Permalink to this definition">¶</a></dt>
<dd>test all loaded plugins.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.test.handle_testsay">
<tt class="descclassname">gozerlib.plugs.test.</tt><tt class="descname">handle_testsay</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.test.handle_testsay" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.test.handle_testsayroot">
<tt class="descclassname">gozerlib.plugs.test.</tt><tt class="descname">handle_testsayroot</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.test.handle_testsayroot" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.test.handle_testsrun">
<tt class="descclassname">gozerlib.plugs.test.</tt><tt class="descname">handle_testsrun</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.test.handle_testsrun" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196</pre></td><td class="code"><div class="highlight"><pre><span class="c"># plugs/test.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="c">## gozerlib imports</span>

<span class="kn">from</span> <span class="nn">gozerlib.utils.exception</span> <span class="kn">import</span> <span class="n">exceptionmsg</span><span class="p">,</span> <span class="n">handle_exception</span>
<span class="kn">from</span> <span class="nn">gozerlib.tests</span> <span class="kn">import</span> <span class="n">tests</span>
<span class="kn">from</span> <span class="nn">gozerlib.commands</span> <span class="kn">import</span> <span class="n">cmnds</span>
<span class="kn">from</span> <span class="nn">gozerlib.examples</span> <span class="kn">import</span> <span class="n">examples</span>
<span class="kn">from</span> <span class="nn">gozerlib.users</span> <span class="kn">import</span> <span class="n">GozerUsers</span>

<span class="c">## basic imports</span>

<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">random</span>

<span class="n">donot</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;gcalc&#39;</span><span class="p">,</span> <span class="p">]</span>

<span class="k">def</span> <span class="nf">dummy</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="k">return</span> <span class="s">&quot;&quot;</span>

<span class="k">def</span> <span class="nf">handle_testplugs</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">msg</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; test all loaded plugins. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="n">msg</span><span class="o">.</span><span class="n">rest</span><span class="p">:</span>
        <span class="n">match</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">rest</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">match</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">users</span> <span class="o">=</span> <span class="n">GozerUsers</span><span class="p">()</span>
        <span class="n">users</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;test@test&#39;</span><span class="p">,],</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">])</span>
    <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
        <span class="k">pass</span>

    <span class="n">bot</span><span class="o">.</span><span class="n">channels</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s">&#39;test&#39;</span><span class="p">,</span> <span class="p">{})</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;--loop&#39;</span><span class="p">])</span>
    <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">):</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="mf">1</span>

    <span class="n">teller</span> <span class="o">=</span> <span class="mf">0</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">loop</span><span class="p">):</span>
        <span class="n">msg</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;starting loop </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
        <span class="n">examplez</span> <span class="o">=</span> <span class="n">examples</span><span class="o">.</span><span class="n">getexamples</span><span class="p">()</span>
        <span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">examplez</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">example</span> <span class="ow">in</span> <span class="n">examplez</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">match</span> <span class="ow">and</span> <span class="n">match</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">example</span><span class="p">:</span>
                <span class="k">continue</span>

            <span class="n">skip</span> <span class="o">=</span> <span class="bp">False</span>

            <span class="k">for</span> <span class="n">dont</span> <span class="ow">in</span> <span class="n">donot</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">dont</span> <span class="ow">in</span> <span class="n">example</span><span class="p">:</span>
                    <span class="n">skip</span> <span class="o">=</span> <span class="bp">True</span>

            <span class="k">if</span> <span class="n">skip</span><span class="p">:</span>
                <span class="k">continue</span>

            <span class="n">teller</span> <span class="o">+=</span> <span class="mf">1</span>
            <span class="n">newmessage</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
            <span class="n">newmessage</span><span class="o">.</span><span class="n">txt</span> <span class="o">=</span> <span class="n">example</span>
            <span class="n">newmessage</span><span class="o">.</span><span class="n">onlyqueues</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="n">msg</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;command: &#39;</span> <span class="o">+</span> <span class="n">example</span><span class="p">)</span>  
            <span class="n">bot</span><span class="o">.</span><span class="n">domsg</span><span class="p">(</span><span class="n">newmessage</span><span class="p">)</span>

            <span class="k">try</span><span class="p">:</span>
                <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;--sleep&#39;</span><span class="p">]))</span>
            <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">):</span>
                <span class="k">pass</span>

    <span class="n">msg</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> tests run&#39;</span> <span class="o">%</span> <span class="n">teller</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test-plugs&#39;</span><span class="p">,</span> <span class="n">handle_testplugs</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;OPER&#39;</span><span class="p">,</span> <span class="p">],</span> <span class="n">options</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;--sleep&#39;</span><span class="p">:</span> <span class="s">&#39;0&#39;</span><span class="p">,</span> <span class="s">&#39;--loop&#39;</span><span class="p">:</span> <span class="s">&#39;1&#39;</span><span class="p">},</span> <span class="n">threaded</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">tests</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test-plugs&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle_testsrun</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>
    <span class="n">toolate</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;--loop&#39;</span><span class="p">]</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">loop</span><span class="p">)</span>
    <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">):</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="mf">1</span>

    <span class="n">tests</span><span class="o">.</span><span class="n">dotests</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">)</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> tests run .. </span><span class="si">%s</span><span class="s"> errors&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">tests</span><span class="o">.</span><span class="n">teller</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">tests</span><span class="o">.</span><span class="n">err</span><span class="p">)))</span>

    <span class="k">if</span> <span class="n">tests</span><span class="o">.</span><span class="n">err</span><span class="p">:</span>
        <span class="n">teller</span> <span class="o">=</span> <span class="mf">0</span>
        <span class="k">for</span> <span class="n">test</span> <span class="ow">in</span> <span class="n">tests</span><span class="o">.</span><span class="n">err</span><span class="p">:</span>
            <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;error #</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">teller</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">test</span><span class="p">)))</span>
            <span class="n">teller</span> <span class="o">+=</span> <span class="mf">1</span>

    <span class="k">if</span> <span class="n">tests</span><span class="o">.</span><span class="n">toolate</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;toolate: &#39;</span><span class="p">,</span> <span class="n">tests</span><span class="o">.</span><span class="n">toolate</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test-run&#39;</span><span class="p">,</span> <span class="n">handle_testsrun</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">,</span> <span class="n">threaded</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;--loop&#39;</span><span class="p">:</span> <span class="s">&#39;1&#39;</span><span class="p">,</span> <span class="s">&#39;--threaded&#39;</span><span class="p">:</span> <span class="s">&#39;False&#39;</span><span class="p">})</span>
<span class="c">#examples.add(&#39;test-run&#39;, &#39;run the tests&#39;, &#39;test-run --sleep 0&#39;)</span>

<span class="k">def</span> <span class="nf">handle_forcedexception</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>
    <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;test exception&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test-forcedexception&#39;</span><span class="p">,</span> <span class="n">handle_forcedexception</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">tests</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test-forcedexception&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle_testhammer</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">msg</span><span class="p">):</span>
    <span class="k">if</span> <span class="n">msg</span><span class="o">.</span><span class="n">rest</span><span class="p">:</span>
        <span class="n">match</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">rest</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">match</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">users</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;test@test&#39;</span><span class="p">,],</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">])</span>
    <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
        <span class="k">pass</span>

    <span class="n">bot</span><span class="o">.</span><span class="n">channels</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s">&#39;test&#39;</span><span class="p">,</span> <span class="p">{})</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;--loop&#39;</span><span class="p">])</span>
    <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">):</span>
        <span class="n">loop</span> <span class="o">=</span> <span class="mf">1</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">hammer</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;--hammer&#39;</span><span class="p">])</span>
    <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">):</span>
        <span class="n">hammer</span> <span class="o">=</span> <span class="mf">10</span>

    <span class="n">teller</span> <span class="o">=</span> <span class="mf">0</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">loop</span><span class="p">):</span>
        <span class="n">msg</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;starting loop </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
        <span class="n">examplez</span> <span class="o">=</span> <span class="n">examples</span><span class="o">.</span><span class="n">getexamples</span><span class="p">()</span>
        <span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">examplez</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">example</span> <span class="ow">in</span> <span class="n">examplez</span><span class="p">:</span>

            <span class="k">if</span> <span class="n">match</span> <span class="ow">and</span> <span class="n">match</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">example</span><span class="p">:</span>
                <span class="k">continue</span>

            <span class="n">skip</span> <span class="o">=</span> <span class="bp">False</span>

            <span class="k">for</span> <span class="n">dont</span> <span class="ow">in</span> <span class="n">donot</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">dont</span> <span class="ow">in</span> <span class="n">example</span><span class="p">:</span>
                    <span class="n">skip</span> <span class="o">=</span> <span class="bp">True</span>

            <span class="k">if</span> <span class="n">skip</span><span class="p">:</span>
                <span class="k">continue</span>

            <span class="n">teller</span> <span class="o">+=</span> <span class="mf">1</span>

            <span class="n">newmessage</span> <span class="o">=</span> <span class="n">cpy</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
            <span class="n">newmessage</span><span class="o">.</span><span class="n">txt</span> <span class="o">=</span> <span class="n">example</span>
            <span class="n">newmessage</span><span class="o">.</span><span class="n">onlyqueues</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="n">msg</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;command: &#39;</span> <span class="o">+</span> <span class="n">example</span><span class="p">)</span>  
            <span class="k">for</span> <span class="n">hammernr</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">hammer</span><span class="p">):</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">bot</span><span class="o">.</span><span class="n">domsg</span><span class="p">(</span><span class="n">newmessage</span><span class="p">)</span>
                <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
                    <span class="n">handle_exception</span><span class="p">()</span>

            <span class="k">try</span><span class="p">:</span>
                <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">options</span><span class="p">[</span><span class="s">&#39;--sleep&#39;</span><span class="p">]))</span>
            <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">):</span>
                <span class="k">pass</span>

    <span class="n">msg</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> tests run&#39;</span> <span class="o">%</span> <span class="n">teller</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test-hammer&#39;</span><span class="p">,</span> <span class="n">handle_testhammer</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test-hammer&#39;</span><span class="p">,</span> <span class="n">handle_testhammer</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">,</span> <span class="n">threaded</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="c">#examples.add(&#39;test-hammer&#39;, &#39;run the hammer tests&#39;, &#39;test-hammer&#39;)</span>
<span class="c">#tests.add(&#39;test-hammer&#39;)</span>

<span class="c">#def handle_tojson(bot, ievent):</span>
<span class="c">#    ievent.reply(ievent.tojson())</span>
<span class="c">#</span>
<span class="c">#cmnds.add(&#39;test-json&#39;, handle_tojson, &#39;OPER&#39;)</span>

<span class="k">def</span> <span class="nf">handle_testsay</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span><span class="n">ievent</span><span class="p">):</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;using </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">ievent</span><span class="o">.</span><span class="n">channel</span><span class="p">)</span>
    <span class="n">bot</span><span class="o">.</span><span class="n">say</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">channel</span><span class="p">,</span> <span class="s">&#39;yoooo!&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test-say&#39;</span><span class="p">,</span> <span class="n">handle_testsay</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">handle_testsayroot</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span><span class="n">ievent</span><span class="p">):</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;using </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">ievent</span><span class="o">.</span><span class="n">channel</span><span class="p">)</span>
    <span class="n">bot</span><span class="o">.</span><span class="n">sayroot</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">channel</span><span class="p">,</span> <span class="s">&#39;yoooo!&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;test-sayroot&#39;</span><span class="p">,</span> <span class="n">handle_testsayroot</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.plugs.test</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="tail.html"
                                  title="previous chapter">gozerlib.plugs.tail</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="uniq.html"
                                  title="next chapter">gozerlib.plugs.uniq</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/plugs/test.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="uniq.html" title="gozerlib.plugs.uniq"
             >next</a> |</li>
        <li class="right" >
          <a href="tail.html" title="gozerlib.plugs.tail"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>